/**
 * 
 */
package cn.pfcg.rally.persistent.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import cn.pfcg.rally.domain.bean.SubjectType;
import cn.pfcg.rally.persistent.dao.SubjectTypeDAO;

/**
 * @author cxq
 *
 */
	public class SubjectTypeDAOImpl implements SubjectTypeDAO {

	private HibernateTemplate hibernateTemplate;
	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.SubjectTypeDAO#getAllSubjects()
	 */
	public List getAllSubjects() {
		return hibernateTemplate.loadAll(SubjectType.class);
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.SubjectTypeDAO#getSubject(java.lang.String)
	 */
	public SubjectType getSubject(String typeName) {
		return (SubjectType) hibernateTemplate.find("from SubjectType subjectType " + "where subjectType.name = ?",typeName).get(0);
	}
	
	/**
	 * @param hibernateTemplate the hibernateTemplate to set
	 */
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void deleteSubjectType(String typeName) {
		SubjectType subjectType = (SubjectType) hibernateTemplate.find("from SubjectType subjectType " + "where subjectType.name = ?",typeName).get(0);
		hibernateTemplate.delete(subjectType);
		
	}

	public void saveSubjectType(SubjectType subjectType) {
		hibernateTemplate.save(subjectType);
		
	}

	public void updateSubjectType(String typeName,SubjectType subject) {
		SubjectType subjectType = (SubjectType) hibernateTemplate.find("from SubjectType subjectType " + "where subjectType.name = ?",typeName).get(0);
		subject.setId(subjectType.getId());
		hibernateTemplate.update(subject);
	}

}
